/* GUI CONVERTED from mfivtr2.i (converter v1.76) Tue May 13 04:15:26 2003 */
/* mfivtr2.i - INCLUDE FILE TO CREATE TRANSACTION FOR SHIPMENT               */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.48 $                                        */

/* REVISION: 8.6      LAST MODIFIED: 11/16/97   BY: *K18W* Taek-Soo Chang    */
/* REVISION: 8.6E     LAST MODIFIED: 05/09/98   BY: *L00Y* Jeff Wootton      */
/* Old ECO marker removed, but no ECO header exists *F003*                   */
/* Old ECO marker removed, but no ECO header exists *F0H4*                   */
/* Old ECO marker removed, but no ECO header exists *F0TC*                   */
/* Old ECO marker removed, but no ECO header exists *F190*                   */
/* Old ECO marker removed, but no ECO header exists *F297*                   */
/* Old ECO marker removed, but no ECO header exists *F358*                   */
/* Old ECO marker removed, but no ECO header exists *F450*                   */
/* Old ECO marker removed, but no ECO header exists *F504*                   */
/* Old ECO marker removed, but no ECO header exists *F805*                   */
/* Old ECO marker removed, but no ECO header exists *F859*                   */
/* Old ECO marker removed, but no ECO header exists *FM97*                   */
/* Old ECO marker removed, but no ECO header exists *FQ11*                   */
/* Old ECO marker removed, but no ECO header exists *FR90*                   */
/* Old ECO marker removed, but no ECO header exists *FT84*                   */
/* Old ECO marker removed, but no ECO header exists *G0BG*                   */
/* Old ECO marker removed, but no ECO header exists *G0V5*                   */
/* Old ECO marker removed, but no ECO header exists *G0YK*                   */
/* Old ECO marker removed, but no ECO header exists *GJ58*                   */
/* Old ECO marker removed, but no ECO header exists *GM13*                   */
/* Old ECO marker removed, but no ECO header exists *H075*                   */
/* Old ECO marker removed, but no ECO header exists *H0X6*                   */
/* Old ECO marker removed, but no ECO header exists *H1C8*                   */
/* Old ECO marker removed, but no ECO header exists *K003*                   */
/* Old ECO marker removed, but no ECO header exists *K04X*                   */
/* Old ECO marker removed, but no ECO header exists *K05G*                   */
/* REVISION: 8.6E     LAST MODIFIED: 06/01/98   BY: *K1NF* Niranjan R.       */
/* REVISION: 8.6E     LAST MODIFIED: 06/08/98   BY: *J2MH* Dana Tunstall     */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* REVISION: 8.6E     LAST MODIFIED: 06/25/98   BY: *L034* Markus Barone     */
/* REVISION: 8.6E     LAST MODIFIED: 12/15/98   BY: *K1YG* Seema Varma       */
/* REVISION: 9.0      LAST MODIFIED: 03/29/99   BY: *J3BM* Reetu Kapoor      */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Vijaya Pakala     */
/* REVISION: 9.0      LAST MODIFIED: 06/22/99   BY: *J3BX* Reetu Kapoor      */
/* REVISION: 8.6      LAST MODIFIED: 10/26/99   BY: *K23Z* Surekha Joshi     */
/* REVISION: 9.1      LAST MODIFIED: 01/11/00   BY: *J3N7* Reetu Kapoor      */
/* REVISION: 9.1      LAST MODIFIED: 06/08/00   BY: *M0ND* Reetu Kapoor      */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KR* myb               */
/* REVISION: 9.1      LAST MODIFIED: 10/04/00   BY: *M0SQ* Santosh Rao       */
/* REVISION: 9.1      LAST MODIFIED: 11/02/00   BY: *M0VS* Abhijeet Thakur   */
/* REVISION: 9.1      LAST MODIFIED: 01/18/01   BY: *M0W0* Rajesh Kini       */
/* REVISION: 9.1      LAST MODIFIED: 09/22/00   BY: *N0WY* Mudit Mehta       */
/* Revision: 1.31     BY: Sandeep P.     DATE: 06/06/01 ECO: *M19F*          */
/* Revision: 1.32     BY: Jeff Wootton   DATE: 09/21/01 ECO: *P01H*          */
/* Revision: 1.33     BY: Anitha Gopal   DATE: 10/18/01 ECO: *M1N1*          */
/* Revision: 1.34     BY: Nikita Joshi   DATE: 01/18/02 ECO: *M1K6*          */
/* Revision: 1.37     BY: Patrick Rowan  DATE: 01/17/01 ECO: *P00G*          */
/* Revision: 1.38     BY: Jeff Wootton   DATE: 05/14/02 ECO: *P03G*          */
/* Revision: 1.40     BY: Patrick Rowan  DATE: 05/24/02 ECO: *P018*          */
/* Revision: 1.41     BY: Steve Nugent   DATE: 06/06/02 ECO: *P07Y*          */
/* Revision: 1.44     BY: Dan Herman     DATE: 06/17/02 ECO: *P091*          */
/* Revision: 1.45     BY: Nishit V       DATE: 06/27/02 ECO: *N1M2*          */
/* Revision: 1.46     BY: Ed van de Gevel  DATE: 09/05/02  ECO: *P0HQ*       */
/* Revision: 1.47     BY: Mamata Samant    DATE: 09/12/02  ECO: *N1TP*       */
/* $Revision: 1.48 $    BY: Narathip W.      DATE: 05/08/03  ECO: *P0RL*       */
/* $Revision: 1.100 $       BY: Joy Huang         DATE: 01/13/04 ECO: *hk-s-020*   */
/*V8:ConvertMode=Maintenance                                                 */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/************************************************************************/

/*!
*/
/*!
    {1} = "input frame bi" for use on delete or modify
    {1} = " " for add
    {2} = "update in_qty_req" to update in_qty_req
    {2} = anything else to prevent update of in_qty_req
*/
/* This is a copy of mfivtr.i modified to handle multiple shipments
 * for a single sales order line item that may be in existence at
 * the same time.  This is included as part of sosoisu5.p. that
 * requires existenece of abs_mstr record for shipments.
 */
/**************************************************************/

{cxcustom.i "MFIVTR2.I"}
define variable l_abs_pick_qty like sod_qty_pick no-undo.
define variable l_flag         like mfc_logical  no-undo.
define variable l_glxcst       like glxcst       no-undo.
define variable l_prev_cost    like sod_std_cost no-undo.
define variable l_trnbr like tr_trnbr no-undo.
define variable l_rmks as character no-undo initial "Consigned Shipment".
define variable sub_total_qty like absr_qty no-undo.
define variable absqty as decimal no-undo.
define variable remaining_qty like absr_qty no-undo.
define variable l_auth as character no-undo.
define variable l_cust_job as character no-undo.
define variable l_cust_seq as character no-undo.
define variable l_cust_ref as character no-undo.
define variable l_dock as character no-undo.
define variable l_line_feed as character no-undo.
define variable l_project as character no-undo.
define variable l_modelyr as character no-undo.
define variable l_first_time as logical initial yes no-undo.
define variable iss_trnbr like tr_trnbr no-undo.
define variable rct_trnbr like tr_trnbr no-undo.
define variable converted_qty as decimal no-undo.
define variable is_wo_issue as logical initial false no-undo.
define variable io_batch like cnsu_batch no-undo.
{&MFIVTR2-I-TAG7}

/* CONSIGNMENT INVENTORY VARIABLES */
{pocnvars.i}

/* DETERMINE IF SUPPLIER CONSIGNMENT IS ACTIVE */
{gprun.i ""gpmfc01.p""
         "(input ENABLE_SUPPLIER_CONSIGNMENT,
           input 11,
           input ADG,
           input SUPPLIER_CONSIGN_CTRL_TABLE,
           output using_supplier_consignment)"}
/*GUI*/ if global-beam-me-up then undo, leave.


if  sod_um_conv = 0 then sod_um_conv = 1.
qty_left = - {1} sod_qty_chg.
find first work_abs_mstr where work_abs_mstr.abs_order = sod_nbr
   and work_abs_mstr.abs_line = string(sod_line)
   and work_abs_mstr.abs_id = item_absid no-lock no-error.

if available work_abs_mstr then do:
   {absupack.i  "work_abs_mstr" 3 22 "l_abs_pick_qty" }
   if confirm_mode then
      assign
         v_confirm_qty = abs_qty * decimal(abs__qad03)
         v_pick_qty    = l_abs_pick_qty * decimal(abs__qad03).

   else
      assign
         v_confirm_qty = -1 * abs_qty * decimal(abs__qad03)
         v_pick_qty    = -1 * l_abs_pick_qty * decimal(abs__qad03).

   /*UPDATE ALLOCATION DETAIL AND LD_QTY_ALL*/
   find lad_det
      where lad_dataset = "sod_det"
      and   lad_nbr     = sod_nbr
      and   lad_line    = string(sod_line)
      and   lad_part    = work_abs_mstr.abs_item
      and   lad_site    = work_abs_mstr.abs_site
      and   lad_loc     = work_abs_mstr.abs_loc
      and   lad_lot     = work_abs_mstr.abs_lot
      and   lad_ref    = work_abs_mstr.abs_ref
   exclusive-lock no-error.

   if available lad_det then do:

      find ld_det
         where ld_part = lad_part
         and   ld_lot  = lad_lot
         and   ld_ref  = lad_ref
         and   ld_site = lad_site
         and   ld_loc = lad_loc
         exclusive-lock no-error.

      if available ld_det then
         ld_qty_all = max ( (ld_qty_all - v_confirm_qty) , 0 ).
      if v_confirm_qty <> v_pick_qty then
         assign
            lad_qty_pick = lad_qty_pick - (v_pick_qty)
            lad_qty_all = max ( ( lad_qty_all -
                          ( v_confirm_qty - v_pick_qty )) ,0).
      else
         lad_qty_pick = lad_qty_pick - v_confirm_qty.
      if lad_qty_all = 0 and lad_qty_pick = 0 then
         delete lad_det.
   end. /* if available lad_det */

   if (not available lad_det)
      and (not confirm_mode)
      and sod_cfg_type <> "2"
   then do:
      create lad_det.
      assign
         lad_dataset = "sod_det"
         lad_nbr = sod_nbr
         lad_line = string(sod_line)
         lad_site = sod_site
         lad_loc = work_abs_mstr.abs_loc
         lad_part = work_abs_mstr.abs_item
         lad_lot = work_abs_mstr.abs_lot
         lad_qty_pick  = (0 - v_pick_qty)
         lad_qty_all = (0 - (v_confirm_qty - v_pick_qty))
         lad_ref = work_abs_mstr.abs_ref.

      if recid(lad_det) = -1 then.

      find ld_det
         where ld_part = lad_part
         and   ld_lot  = lad_lot
         and   ld_ref  = lad_ref
         and   ld_site = lad_site
         and   ld_loc  = lad_loc
         exclusive-lock no-error.
      if available ld_det then
         ld_qty_all = ld_qty_all - v_confirm_qty.

      /* CREATING LD_DET RECORD FOR THE LOT WHICH WAS      */
      /* CONSUMED FULLY DURING CONFIRMATION OF THE SHIPPER */
      if not available ld_det then
      do:
         create ld_det.
         assign
            ld_part    = lad_part
            ld_lot     = lad_lot
            ld_ref     = lad_ref
            ld_site    = lad_site
            ld_loc     = lad_loc
            ld_qty_all = -1 * v_confirm_qty.

         for first loc_mstr
            fields (loc_date loc_loc loc_perm loc_site loc_status)
            where  loc_site = lad_site
            and    loc_loc  = lad_loc
         no-lock:
         end. /* FOR FIRST loc_mstr */
         if available loc_mstr
         then
            ld_status = loc_status.

         if recid(ld_det) = -1 then.
      end. /* IF NOT AVAILABLE LD_DET */
   end.

end. /* if available work_abs_mstr */

/* DELETE KIT COMPONENT DETAIL ALLOCATIONS */
{gprun.i ""soktdel2.p"" "(input recid(sod_det), input item_absid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


/* RETRIEVING THE QUANTITY IN INVENTORY UM */
/* FOR A SO CREATED IN ALTERNATE UM        */

if sod_um_conv <> 1 then do:
   qty_left = 0.
   for each sr_wkfl
         where sr_userid       = mfguser
         and   trim(sr_lineid) = trim(string(sod_line)) no-lock:
      qty_left = qty_left + ( - decimal(sr__qadc01)).
   end.  /* FOR EACH SR_WKFL */
end. /* IF SOD_UM_CONV <> 0 */

prev_found = no.
do for sr_wkfl while qty_left <> 0:
   trqty = qty_left.
   site = {1} sod_site.
   if location = "" then location = {1} sod_loc.
   if lotser = "" then lotser = {1} sod_serial.

   /* CHECK TO SEE IF ITEM SERIAL NUMBER CONTROLLED */
   find first sr_wkfl where sr_userid = mfguser
      and   trim(sr_lineid) = trim(string(sod_line))
      exclusive-lock no-error.
   if available sr_wkfl then do:
      assign
         site     = sr_site
         location = sr_loc
         lotser   = sr_lotser
         lotrf    = sr_ref
         trqty    = if sod_um_conv <> 1 then
                       (- decimal(sr__qadc01))
                    else
                       - sr_qty.

      delete sr_wkfl.
   end.
   {&MFIVTR2-I-TAG1}

   if site <> sod_site and sod_type <> "m" then do:
      {&MFIVTR2-I-TAG2}
      assign
         global_part = sod_part
         global_addr = so_cust
         transtype = "ISS-SO".
      {&MFIVTR2-I-TAG3}

      if not available pt_mstr then

      /* ADDED PT_CFG_TYPE IN THE FIELD LIST FOR PT_MSTR       */
      for first pt_mstr
         fields (pt_abc pt_avg_int pt_bom_code pt_cyc_int pt_desc1
                 pt_desc2 pt_insp_lead pt_insp_rqd pt_joint_type
                 pt_loc pt_mfg_lead pt_mrp pt_network pt_ord_max
                 pt_ord_min pt_ord_mult pt_ord_per pt_ord_pol
                 pt_ord_qty pt_part pt_plan_ord pt_pm_code
                 pt_prod_line pt_pur_lead pt_rctpo_active
                 pt_rctpo_status pt_rctwo_active pt_rctwo_status
                 pt_routing pt_sfty_time pt_shelflife pt_timefence
                 pt_um pt_yield_pct pt_cfg_type)
         where pt_part = sod_part no-lock:
      end. /* FOR FIRST PT_MSTR */

      {gprun.i ""icxfer.p"" "(trlot,
                              lotser,
                              lotrf,
                              lotrf,
                              -1 * trqty,
                              {1} sod_nbr,
                              {1} sod_nbr,
                              """",
                              """",
                              eff_date,
                              site,
                              location,
                              sod_site,
                              if available pt_mstr then
                                pt_loc else location,
                              no,
                              l_shipper,
                              l_shp_date,
                              l_inv_mov,
                              0,
                              output glcost,
                              output iss_trnbr,
                              output rct_trnbr,
                              input-output assay,
                              input-output grade,
                              input-output expire)"
         }
/*GUI*/ if global-beam-me-up then undo, leave.

      {&MFIVTR2-I-TAG8}
   end.

   if available pl_mstr then
      for first pld_det
         fields (pld_inv_acct pld_inv_sub pld_inv_cc
                 pld_loc pld_prodline pld_site)
         where pld_prodline = pl_prod_line and pld_site = sod_site
         no-lock:
   end. /* FOR FIRST PLD_DET */
   assign
      trgl_recno = ?
      sct_recno  = ?
      glxcst = 0
      gl_amt = 0
      dr_acct = ""
      dr_sub  = ""
      dr_cc = ""
      .

   base-price = {1} sod_price / {1} sod_um_conv.
   if so_curr <> base_curr then do:
      /* CONVERT PRICE TO BASE CURRENCY */
      {gprunp.i "mcpl" "p" "mc-curr-conv"
         "(input  so_curr,
           input  base_curr,
           input  exch_rate,
           input  exch_rate2,
           input  base-price,
           input  no,   /* DO NOT ROUND */
           output base-price,
           output mc-error-number)"}
   end.  /* if so_mstr.so_curr <> base_curr */

   assign
      l_prev_cost = sod_std_cost
      l_glxcst    = 0.

   /* CALCULATING SOD_STD_COST (EMT SO) FOR ATO ITEMS */
   /* TO REFLECT ENTIRE CONFIGURATION COST            */
   if (sod_btb_type = "02" or
      sod_btb_type = "03") and
      can-find (first pt_mstr
      where pt_part     = sod_part
        and pt_pm_code  = "c"
        and pt_cfg_type = "1") then
   do:

      sod_std_cost = 0.
      {gpsct05.i &part=sod_part &site=sod_site &cost=sct_cst_tot}

      assign
         sod_std_cost = glxcst
         l_flag = yes.

      for each sob_det
         fields (sob_line sob_nbr sob_part sob_qty_req
                 sob_serial sob_site)
         where sob_nbr  = sod_nbr
           and sob_line = sod_line no-lock
         break by sob_part:
/*GUI*/ if global-beam-me-up then undo, leave.


         if first-of(sob_part) then
            qty_req = 0.

         if substring(sob_serial,15,1) = "o" then
            qty_req = qty_req + sob_qty_req.

         if last-of(sob_part) and
            qty_req <> 0 then
         do:
            {gprun.i ""gpsct05.p""
               "(input sob_part, sob_site, input 1,
                  output glxcst, output curcst)"}
/*GUI*/ if global-beam-me-up then undo, leave.

            assign
               glxcst = glxcst * (sob_qty_req
                      / (sod_qty_ord * sod_um_conv))
               sod_std_cost = sod_std_cost + glxcst
               l_glxcst     = l_glxcst     + glxcst.
         end. /* IF LAST-OF */
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH SOB_DET */
   end. /* IF (SOD_BTB_TYPE = "02" ... */

   if available pt_mstr
   then do:
      {gpsct06.i &part=sod_part
                 &site=sod_site
                 &type=""GL""}
   end. /* IF AVAILABLE pt_mstr */

   assign
      sct_recno = recid(sct_det)
      recno     = sct_recno.

   /* IF THE ORDER BEING SHIPPED IS A CONSIGNMENT ORDER    */
   /* THEN RUN PROGRAM icxfer3.p TO TRANSFER MATERIALS     */
   /* INTO THE APPROPRIATE CONSIGNMENT LOCATION. OTHERWISE */
   /* RUN THE EXISTING ictrans.i TO RECORD THE SHIPMENT    */

   /* NOT CONSIGNED, OR CONSIGNED AND SHIPPED */
   if work_abs_mstr.abs_consign_flag and
      ((confirm_mode and v_confirm_qty > 0) or
      (not confirm_mode and v_confirm_qty < 0)) then do:

      assign
         global_part = sod_part
         global_addr = so_cust.

      {gprun.i ""icxfer.p""
         "(trlot,
           lotser,
           lotrf,
           lotrf,
           -1 * trqty,
           {1} sod_nbr,
           {1} sod_nbr,
           l_rmks,
           l_project,
           eff_date,
           site,
           location,
           sod_site,
           work_abs_mstr.abs_transfer_to_loc,
           no,
           l_shipper,
           l_shp_date,
           l_inv_mov,
           0,
           output glcost,
           output iss_trnbr,
           output rct_trnbr,
           input-output assay,
           input-output grade,
           input-output expire)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /* CREATE CN-SHP TRANSACTION */
      l_trnbr = rct_trnbr.
      {gprunmo.i
         &program = "icxfer3.p"
         &module = "ACN"
         &param = """(input trlot,
           input lotser,
           input lotrf,
           input lotrf,
           input v_confirm_qty,
           input {1} sod_nbr,
           input {1} sod_nbr,
           input {1} sod_line,
           input l_rmks,
           input l_project,
           input eff_date,
           input site,
           input location,
           input sod_site,
           input work_abs_mstr.abs_transfer_to_loc,
           input no,
           input l_shipper,
           input eff_date,
           input l_inv_mov,
           input work_abs_mstr.abs_consign_dr_acct,
           input work_abs_mstr.abs_consign_dr_sub,
           input work_abs_mstr.abs_consign_dr_cc,
           input work_abs_mstr.abs_consign_cr_acct,
           input work_abs_mstr.abs_consign_cr_sub,
           input work_abs_mstr.abs_consign_cr_cc,
           input so_curr,
           input base-price,
           input sod_qty_ord - sod_qty_ship,
           output glcost,
           input-output l_trnbr,
           input-output assay,
           input-output grade,
           input-output expire)"""}

      absqty = abs_qty * decimal(abs__qad03).


      /*** SEQUENCES ***/

      for each abss_det where abss_shipfrom = abs_shipfrom and
               abss_abs_id   = work_abs_mstr.abs_id  and
               abss_order    = work_abs_mstr.abs_order   and
               abss_line     = integer(work_abs_mstr.abs_line)
      no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


          sub_total_qty = sub_total_qty + (abss_qty * decimal(abs__qad03)).

           /* CREATE CONSIGNMENT SHIPMENT-INVENTORY X-REF */

           /* VARIABLE l_first_time  gets passed to and from socncix.p   */
           /* When l_first_Time is YES, then socncix.p will create a new */
           /* cross reference record. When l_first_time becomes NO then */
           /* socncix.p will update the same cross reference record as   */
           /* long as the other key data is the same.                    */
           converted_qty = abss_qty * decimal(abs__qad03).
           {gprunmo.i
                  &program = "socncix.p"
                  &module = "ACN"
                  &param = """(input sod_nbr,
                               input sod_line,
                               input sod_site,
                               input l_shp_date,
                               input (if confirm_mode then
                                         converted_qty
                                         else - converted_qty),
                               input abs__qad02,
                               input l_shipper,
                               input l_trnbr,
                               input work_abs_mstr.abs_transfer_to_loc,
                               input abs_lotser,
                               input abs_ref,
                               input l_auth,
                               input abss_cust_job,
                               input abss_cust_seq,
                               input abss_cust_ref,
                               input abss_dock,
                               input abss_line_feed,
                               input l_modelyr,
                               input true,
                               input-output l_first_time)"""}

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* for each abss_det */

      /*** AUTHORIZATIONS ***/

      if sub_total_qty < abs_qty then do:
         for each absr_det where absr_shipfrom = abs_shipfrom and
            absr_id       = work_abs_mstr.abs_id  and
            absr_type     = 3       and
            absr_nbr      = work_abs_mstr.abs_order   and
            absr_line     = integer(work_abs_mstr.abs_line)
         no-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


            sub_total_qty = sub_total_qty + (absr_qty * decimal(abs__qad03)).

            /* CREATE CONSIGNMENT SHIPMENT-INVENTORY X-REF */


            /* VARIABLE l_first_time  gets passed to and from socncix.p   */
            /* When l_first_Time is YES, then socncix.p will create a new */
            /* cross reference record. When l_first_time becomes NO then */
            /* socncix.p will update the same cross reference record as   */
            /* long as the other key data is the same.                    */
           converted_qty = absr_qty * decimal(abs__qad03).
           {gprunmo.i
               &program = "socncix.p"
               &module = "ACN"
               &param = """(input sod_nbr,
                            input sod_line,
                            input sod_site,
                            input l_shp_date,
                            input (if confirm_mode then
                                      converted_qty
                                   else - converted_qty),
                            input abs__qad02,
                            input l_shipper,
                            input l_trnbr,
                            input work_abs_mstr.abs_transfer_to_loc,
                            input abs_lotser,
                            input abs_ref,
                            input absr_reference,
                            input l_cust_job,
                            input l_cust_seq,
                            input l_cust_ref,
                            input l_dock,
                            input l_line_feed,
                            input l_modelyr,
                            input true,
                            input-output l_first_time)"""}

         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* for each absr_det */
      end. /* if sub_total_qty < abs_qty */

      if sub_total_qty < absqty      then do:

         /* Create consignment shipment-inventory x-ref */

         {gprunmo.i
            &program = "socncix.p"
            &module = "ACN"
            &param = """(input sod_nbr,
              input sod_line,
              input sod_site,
              input l_shp_date,
              input (if confirm_mode then
              absqty - sub_total_qty
              else - (absqty - sub_total_qty)),
              input abs__qad02,
              input l_shipper,
              input l_trnbr,
              input work_abs_mstr.abs_transfer_to_loc,
              input abs_lotser,
              input abs_ref,
              input l_auth,
              input l_cust_job,
              input l_cust_seq,
              input l_cust_ref,
              input l_dock,
              input l_line_feed,
              input l_modelyr,
              input true,
              input-output l_first_time)"""}

      end. /*if sub_total_qty*/

      /* RETRIEVE THE ISS-TR tr_hist TO LATER SAVE THE REC-ID */
      /* AND TO REDUCE THE REQUIRED QTY IN INVENTORY MASTER.  */
      for first tr_hist
         where  tr_trnbr = iss_trnbr
         no-lock:
         end.

   end.  /* if work_abs_mstr.abs_consigned_flag */
   else do:

   /* ADDED SECOND EXCHANGE RATE, TYPE, SEQUENCE               */
   /* CHANGED PRICE PARAM TO USE BASE-PRICE                    */
   /* ADDED 3 INPUT PARAMTERS &SHIPNBR &SHIPDATE AND &INVMOV   */
   /* ADDED PARAMETERS &crsub and &drsub                       */
   /* CHANGED TWENTYSEVENTH PARAMETER &QUANTITY VALUE TO TRQTY */
   /* FROM TRQTY * {1} SOD_UM_CONV                             */
   {&MFIVTR2-I-TAG4}
   {ictrans.i
      &addrid=so_cust
      &bdnstd=0
      &cracct="
                  if available pt_mstr then
                     if available pld_det then pld_inv_acct
                     else pl_inv_acct
                  else """""
      &crsub="
                  if available pt_mstr then
                     if available pld_det then pld_inv_sub
                     else pl_inv_sub
                  else """""
      &crcc="
                  if available pt_mstr then
                     if available pld_det then pld_inv_cc
                     else pl_inv_cc
                  else """""
      &crproj="{1} sod_project"
      &curr=so_curr
      &dracct=dr_acct
      &drsub=dr_sub
      &drcc=dr_cc
      &drproj="{1} sod_project"
      &effdate=eff_date
      &exrate=exch_rate
      &exrate2=exch_rate2
      &exratetype=exch_ratetype
      &exruseq=exch_exru_seq
      &glamt=gl_amt
      &invmov=l_inv_mov
      &lbrstd=0
      &line="{1} sod_line"
      &location="(if site <> sod_site and available pt_mstr
                  then pt_loc else location)"
      &lotnumber=trlot
      &lotserial=lotser
      &lotref=lotrf
      &mtlstd="if sod_type = 'M' and not available pt_mstr
               then sod_std_cost else 0"
      &ordernbr="{1} sod_nbr"
      &ovhstd=0
      &part=sod_part
      &perfdate="{1} sod_per_date"
      &price=base-price
      &promisedate="{1} sod_promise_date"
      &quantityreq= "if new sod_det then
                      ({1} sod_bo_chg + {1} sod_qty_chg) * {1} sod_um_conv
                     else
                      ({1} sod_qty_ord - {1} sod_qty_ship) * {1} sod_um_conv"
      &quantityshort="{1} sod_bo_chg * {1} sod_um_conv"
      &quantity="trqty"
      &revision=""""
      &rmks=""""
      &shipdate=l_shp_date
      &shipnbr=l_shipper
      &shiptype="{1} sod_type"
      &site=sod_site
      &slspsn1="{1} sod_slspsn[1]"
      &slspsn2="{1} sod_slspsn[2]"
      &slspsn3="tr_slspsn[3] = {1} sod_slspsn[3]"
      &slspsn4="tr_slspsn[4] = {1} sod_slspsn[4]"
      &sojob="if sod_fsm_type begins """RMA""" then
                 {1} sod_contr_id
              else
                 {1} sod_nbr"
      &substd=0
      &transtype=""ISS-CSR""
      &msg=0
      &ref_site=tr_site
      &tempid=1
      &trordrev="tr_ord_rev = so_rev"
      }
   {&MFIVTR2-I-TAG9}

   {&MFIVTR2-I-TAG6}

   /* CREATE CONSIGNMENT USAGE RECORDS IF CONSIGNMENT ENABLED*/
   /* AND CONSIGNMENT INVENTORY EXISTS.                      */
   if using_supplier_consignment then do:
      {gprunmo.i
         &program = ""pocnsix4.p""
         &module  = "ACN"
         &param   =  """(input sod_part,
                         input site,
                         input right-trim(substring(lotser,1,18)),
                         input lotrf,
                          output consign_flag)"""}

            /*IF CONSIGNED INVENTORY EXISTS, DETERMINE WHETHER TO */
            /*USE IT PRIOR TO UNCONSIGNED INVENTORY.              */
      if consign_flag then do:
         {gprunmo.i
            &program = ""ictrancn.p""
            &module  = "ACN"
            &param   =  """(input sod_nbr,
                            input '',
                            input 0,
                            input tr_so_job,
                            input - trqty,
                            input lotser,
                            input sod_part,
                            input site,
                            input location,
                            input lotrf,
                            input eff_date,
                            input tr_trnbr,
                            input is_wo_issue,
                            input-output io_batch)"""}

      end. /*If consign_flag*/
   end. /*IF USING_SUPPLIER_CONSIGNMENT*/

   {&MFIVTR2-I-TAG5}

   /* THE RECID OF THE tr_hist RECORD CREATED HAS TO BE PASSED */
   /* TO socost01.p. SINCE THE tr_hist IS CREATED IN ictrans.i */
   /* THE CALL TO socost01.p SHOULD BE MADE AFTER THE CALL TO  */
   /* ictrans.i */

   /* THE ADDITIONAL INPUT PARAMETER recid(tr_hist) IS PASSED TO    */
   /* socost01.p SO THAT WHEN THE TRANSACTION DETAIL IS CREATED FOR */
   /* THE MIRROR ACCOUNT,THE TRANSACTION NUMBER IS ASSIGNED FROM    */
   /* THE TRANSACTION HISTORY.                                      */

   {gprun.i ""socost01.p""
      "(trqty,
        lotser,
        prev_found,
        sod_entity,
        location,
        recid(tr_hist) )"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /* prev_found AND recno HAVE TO BE ASSIGNED AFTER THE  CALL */
   /* TO socost01.p IS MADE                                    */
   assign
      prev_found = yes
      recno      = sct_recno.

   if available pt_mstr and sod_prodline <> pt_prod_line then
      if sod_fsm_type = "" and sod_rma_type = "" then
      do for soddet:
         find soddet where soddet.sod_nbr = sod_det.sod_nbr and
         soddet.sod_line = sod_det.sod_line
         exclusive-lock no-error.
         if available soddet then
            soddet.sod_prodline = pt_prod_line.
      end.

   assign
      tr_prod_line = sod_prodline
      tr_fsm_type  = sod_fsm_type
      tr_ship_date = so_ship_date.

   if site <> sod_site then
   assign
      tr_assay = assay
      tr_grade = grade.
      tr_expire = expire.

   /* CALCULATING MATERIAL COST, GL AMOUNT BASED ON THE ENTIRE */
   /* CONFIGURATION STRUCTURE OF ATO ITEM                      */
   if l_flag then
      assign
         tr_mtl_std   = sod_std_cost
         sod_std_cost = sod_std_cost * sod_um_conv
         l_glxcst     = l_glxcst  * absolute(trqty)
         tr_gl_amt    = l_glxcst
         trgl_gl_amt  = l_glxcst.

   l_flag = no.

   /* CHANGED FIRST PARAMETER TO TRQTY */
   /* FROM TRQTY * {1} SOD_UM_CONV     */
   {gprun.i ""socost02.p"" "(trqty, sod_entity,
                     recid(trgl_det), recid(tr_hist) )"}
/*GUI*/ if global-beam-me-up then undo, leave.


   end.  /* ELSE DO - if work_abs_mstr.abs_consigned_flag */

   tr_recno = recid(tr_hist).

   /* DO NOT UPDATE IN_QTY_REQ FOR RMA RECEIPT LINES */
   if {1} sod_type = ""
      and not {1} sod_sched
      and ({1} sod_fsm_type <> "RMA-RCT")
   then do:
      if not site_change then do:
         find in_mstr where in_part = {1} sod_part and in_site = {1}
            sod_site exclusive-lock no-error.

         if available in_mstr then do:
            if {2} = "update in_qty_req"
            then do:
               if pend_inv then
                  assign in_qty_req = in_qty_req + tr_qty_loc.
               else do: /* not pend_inv */
                  /* Update Qty Required on in_mstr.  Note: tr_qty_loc is */
                  /* negative on shipments, positive on cr order returns. */
                  /* sod_qty_ship hasn't been updated w/new shipment yet. */
                  /* code with conversion factor sod_um_conv */
                  if {1} sod_qty_ord >= 0 then      /* Order Shipment */
                     in_qty_req = in_qty_req -
                        MAX(({1} sod_qty_ord * {1} sod_um_conv -
                        {1} sod_qty_ship * {1} sod_um_conv),0) +
                        MAX({1} sod_qty_ord * {1} sod_um_conv -
                        ({1} sod_qty_ship * {1} sod_um_conv - tr_qty_loc),0).
                  if {1} sod_qty_ord < 0 then       /* Cr Order Return */
                     in_qty_req = in_qty_req -
                        MIN(({1} sod_qty_ord * {1} sod_um_conv -
                        {1} sod_qty_ship * {1} sod_um_conv),0) +
                        MIN({1} sod_qty_ord * {1} sod_um_conv  -
                        ({1} sod_qty_ship * {1} sod_um_conv - tr_qty_loc),0).
               end.   /* not pend invoice */
            end. /* {2} = update in_qty_req */
         end.   /* avail in_mstr */
      end.   /* not site_change */
   end.   /* sod_type = "" */
   qty_left = qty_left - trqty.

end.
